package com.test.book.model;

import lombok.Data;

@Data
public class Result <T>{
    private ResultStatus status;
    private String errorMessage;
    private T data;

//    业务执行成功返回的代码
    public static <T> Result success(T data){
        Result result = new Result();
        result.setStatus(ResultStatus.SUCCESS);
        result.setErrorMessage("");
        result.setData(data);
        return result;
    }

    public static Result unLogin(){
        Result result = new Result();
        result.setStatus(ResultStatus.UNLOGIN);
        result.setErrorMessage("用户未登录");
        result.setData(null);
        return result;
    }

    public static Result fail(String message){
        Result result = new Result();
        result.setStatus(ResultStatus.FAIL);
        result.setErrorMessage(message);
        result.setData(null);
        return result;
    }
}
